Skip to content

fix(cli): mistyped group subcommand errors with a suggestion instead of exiting 0 (#75)#175

Merged
saadqbal merged 1 commit into
developfrom
fix/75-group-typo-guard
Jul 8, 2026
Merged

fix(cli): mistyped group subcommand errors with a suggestion instead of exiting 0 (#75)#175
saadqbal merged 1 commit into
developfrom
fix/75-group-typo-guard

Conversation

@LukasWodka

Copy link
Copy Markdown
Contributor

Closes #75.

Problem

tracebloc data ingst (and the same for cluster, auth, client) printed the group's help and exited 0 — a mistyped subcommand looked like success. Verified on develop: data ingst, cluster inf, client lst all exit 0.

Root cause (corrects the issue's proposed fix): a parent command with subcommands but no Run/RunE is not runnable, and cobra short-circuits a non-runnable command to flag.ErrHelp before it validates args (command.go: if !c.Runnable() { return flag.ErrHelp } precedes ValidateArgs). So the unknown token never reached validation. cobra.NoArgs does not fix this — it's an arg validator, never reached on a non-runnable command.

Fix

Give the four group commands a RunE: runGroup (in root.go):

  • bare tracebloc <group> → prints help, exits 0 (unchanged);
  • mistyped subcommand → hard error, exit 1, with a nearest-match suggestion, mirroring the unknown command wording the root already emits via cobra's default legacyArgs.

SuggestionsMinimumDistance: 2 drives the hint; SuggestionsFor skips hidden commands, so the Rev-9 hidden client list is never suggested. The root command is untouched (it already errored correctly).

$ tracebloc data ingst
Error: unknown command "ingst" for "tracebloc data"

Did you mean this?
	ingest

Run 'tracebloc data --help' for the available commands.   # exit 1

Tests (internal/cli/group_test.go)

  • UnknownSubcommand_Errors — all four groups + the dataset alias, asserts non-zero exit + "unknown command".
  • UnknownSubcommand_Suggests — nearest-match hint (ingstingest, infinfo, doctrdoctor).
  • HiddenSubcommand_NotSuggestedclient lst must not surface the hidden list.
  • Bare_StillHelpsExitZero — bare group still helps + exits 0.

The error cases are verified to fail without the fix. Full internal/... suite + go vet + gofmt green.

Targets develop. Isolated to root.go + the four group constructors — no overlap with the open ingest-path PRs.

🤖 Generated with Claude Code

…of exiting 0 (#75)

`tracebloc data ingst` (and cluster/auth/client typos) printed the group's
help and exited 0, silently swallowing the mistake. A parent command with
subcommands but no Run/RunE is "not runnable", and cobra short-circuits a
non-runnable command to flag.ErrHelp BEFORE it validates args — so the
unknown token never reached arg validation. (The issue's suggested
`cobra.NoArgs` does NOT fix this: it's an arg validator, never reached on a
non-runnable command.)

Give the four group commands (data, cluster, auth, client) a RunE=runGroup:
a bare `tracebloc <group>` still prints help and exits 0, but a mistyped
subcommand is now a hard error (exit 1) with a nearest-match suggestion,
matching the "unknown command" wording the root already emits via its
default legacyArgs. SuggestionsMinimumDistance=2 drives the hint;
SuggestionsFor skips hidden commands, so the Rev-9 hidden `client list` is
never suggested. The root command is unchanged — as the parent-less command
it already errored on unknown tokens.

Tests: internal/cli/group_test.go — unknown-subcommand-errors (across all
four groups + the `dataset` alias), nearest-match suggestion, hidden-list
not suggested, bare-group-still-helps. The error cases are verified to fail
without the fix (unfixed groups print help + exit 0). Full internal suite +
vet + gofmt green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LukasWodka LukasWodka self-assigned this Jul 7, 2026
@LukasWodka LukasWodka requested a review from saadqbal July 7, 2026 19:59
@saadqbal

saadqbal commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Clean, well-tested fix 👍 — root-cause writeup is spot on, and I verified the behavior end-to-end (typo → exit 1 + suggestion, bare group → help/exit 0, hidden client list correctly not suggested).

Tiny thing: the group message isn't quite "identical" to root's — it appends a Run 'tracebloc data --help' for the available commands. trailer that cobra's native root "unknown command" message doesn't emit. It's a nice extra line, so if anything worth adding to root for real symmetry rather than dropping it.

@saadqbal saadqbal merged commit 95f5a64 into develop Jul 8, 2026
17 checks passed
@saadqbal

saadqbal commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

/fr-pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants